const Base = require('./base.js');
module.exports = class extends Base {
	constructor(ctx) {
		super(ctx);
		this.refund = this.model('store/refund');
		this.order_goods = this.model('store/order_goods');
	}
	async indexAction() {
		if(this.isGet) {
			return this.display();
		}

		let posts = this.post();

		let where = {};
		if(!think.isEmpty(posts.userid)){
			where.user_id = posts.userid;
		}
		const data = await this.refund.dataTable(posts, where);
		console.log(JSON.stringify(data))
		return this.json(data);
	}
	
	async detailAction(){
		if(this.isGet) {
			let gets = this.get();			
			let refund = await this.refund.findOne(gets.id);
			refund.goods = await this.order_goods.findOne(refund.order_goods_id);
			this.assign("refund",refund);
			return this.display();
		}
	}
	
	async dealAction(){
		let posts = this.post();		
		console.log(posts)
		let user = await this.session("user");
		let data = {
			status: posts.status,
			admin_id: user.id,
			deal_idea:posts.deal_idea,
			deal_time: new Date().valueOf()
		};
		
		await this.refund.setOne(posts.id,data);
		return this.success();
		
	}
};